package src.java.easy;

import java.util.BitSet;
import java.util.LinkedHashSet;

/**
 * @author 袁敏
 * @className Solution415
 * @date 2024/7/26
 * @description TODO
 */
public class Solution415 {
    public static void main(String[] args) {
        String num1 = "9";
        String num2 = "99";
        System.out.println(addStrings(num1, num2));
    }

    public static String addStrings(String num1, String num2) {
        int index1 = num1.length() - 1;
        int index2 = num2.length() - 1;
        StringBuilder sb = new StringBuilder();
        int sum = 0;
        while (index1 >= 0 || index2 >= 0 || sum != 0) {
            int n1 = index1 >= 0 ? num1.charAt(index1) - '0' : 0;
            int n2 = index2 >= 0 ? num2.charAt(index2) - '0' : 0;
            sum += n1 + n2;
            sb.append(sum % 10);
            sum /= 10;
            index1--;
            index2--;
        }
        sb.reverse();
        return sb.toString();
    }
}
